#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200000 + 7;
int a[N];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  vector<int> v[n + 1];
  for (int i = 0; i <= n; ++i) {
    v[i].push_back(-(int)1e9 - 7);
  }
  for (int i = 0; i < n; ++i) {
    int l = 0, r = n;
    while (r - l > 1) {
      int m = (l + r) / 2;
      if (v[m].back() <= a[i]) {
        r = m;
      } else {
        l = m;
      }
    }
    v[r].push_back(a[i]);
  }
  for (int i = 0; i <= n; ++i) {
    if (v[i].size() > 1) {
      for (int j = 1; j < (int)v[i].size(); ++j) {
        cout << v[i][j] << ' ';
      }
      cout << '\n';
    }
  }
}
